package cn.rokhdelar.ams.management.controller;

import cn.rokhdelar.ams.common.domain.vo.PageVO;
import cn.rokhdelar.ams.management.domain.query.UserQuery;
import cn.rokhdelar.ams.management.domain.vo.UserVO;
import cn.rokhdelar.ams.management.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author Rokhdelar
 * @since 2024/10/18 -- 10:43
 **/

@RestController
@RequestMapping(value = "/management/users")
@RequiredArgsConstructor
@Schema(title = "系统用户接口")
@Tag(name = "系统用户接口")
public class UserController {
    private final SysUserService userService;

    @GetMapping
    @Operation(description = "根据查询条件分页返回系统用户信息")
    public ResponseEntity<PageVO<UserVO>> getUserByPage(@ParameterObject UserQuery query) {
        return ResponseEntity.ok(userService.getUserListByPage(query));
    }

    @GetMapping(value = "/{id}")
    @Operation(description = "根据ID查询用户信息")
    public ResponseEntity<UserVO> getUserById(@PathVariable String id) {
        return ResponseEntity.ok(userService.getUserById(id));
    }

    @PostMapping
    @Operation(description = "新建用户")
    public ResponseEntity<Boolean> createUser(@RequestBody UserVO userVO) {
        return ResponseEntity.ok(userService.createUser(userVO));
    }

    @PatchMapping(value = "/{id}")
    @Operation(description = "根据ID更新用户")
    public ResponseEntity<Boolean> updateUser(@PathVariable String id, @RequestBody UserVO userVO) {
        return ResponseEntity.ok(userService.updateUser(userVO));
    }

    @PostMapping(value = "/resetpassword")
    @Operation(summary = "重置密码", description = "重置密码")
    public ResponseEntity<Boolean> resetpassword( @RequestBody UserVO userVO) {
        return ResponseEntity.ok(userService.resetPassWord(userVO));
    }



    @DeleteMapping(value = "/{id}")
    @Operation(description = "根据用户ID删除用户")
    public ResponseEntity<Boolean> deleteUser(@PathVariable String id) {
        return ResponseEntity.ok(userService.deleteUserById(id));
    }
}
